package controller

import (
	"golang.org/x/net/context"
	"lot_admin_api/api"

	"lot_admin_api/internal/model"
	"lot_admin_api/internal/service"
)

var Auth = cAuth{}

type cAuth struct{}

// AddAuth  新增权限
func (h *cAuth) AddAuth(ctx context.Context, req *api.AddAuthReq) (res *model.AuthIdRes, err error) {
	id, err := service.Auth().AddAuth(ctx, req)
	res = &model.AuthIdRes{
		Id: id,
	}
	return res, err
}

// UpdateAuth 编辑权限
func (h *cAuth) UpdateAuth(ctx context.Context, req *api.UpdateAuthReq) (res *model.AuthIdRes, err error) {
	Id, err := service.Auth().UpdateAuth(ctx, req)
	var info = &model.AuthIdRes{
		Id: Id,
	}
	return info, err
}

// DeleteAuth  删除权限
func (h *cAuth) DeleteAuth(ctx context.Context, req *api.DeleteAuthReq) (res *model.AuthIdRes, err error) {
	Id, err := service.Auth().DeleteAuth(ctx, req)
	var info = &model.AuthIdRes{
		Id: Id,
	}
	return info, err
}

// GetInfoAuth  获取当前权限的详情
func (h *cAuth) GetInfoAuth(ctx context.Context, req *api.GetInfoAuthReq) (res *model.AuthTreeInfoRes, err error) {
	res, err = service.Auth().GetInfoAuth(ctx, req)
	return res, err
}

// GetTreeAuth  获取权限的树结构
func (h *cAuth) GetTreeAuth(ctx context.Context, req *api.GetTreeAuthReq) (treeInfo []*model.AuthTreeInfoRes, err error) {
	findOne, err := service.Auth().GetTreeAuth(ctx, req)
	treeInfo = append(treeInfo, findOne)
	return treeInfo, err
}
